#ifdef MBM_IMIWORLD_SUPPORT
#include "mbm_mstar_inc.h"

#include "mbm_typedefine.h"
#include "mbm_sys_adapter.h"
#include "mbm_vui_adapter.h"


#include "mbm_am_adapter.h"

#include "ven_ts.h"
//macro

//extern variable

//extern function

//static or gloable variable
static t_mbm_keyhandler g_am_key_handler = NULL;
static t_mbm_tphandler g_am_tp_handler = NULL;
static t_mbm_applet_state_handler g_am_state_handler = NULL;



void mbm_am_key_handler(UInt8 event, UInt8 code)
{
	UInt32 evt = 0, cd = 0;

	mbm_trace("mbm_am_key_handler g_am_key_handler=%d", g_am_key_handler);

	evt = mbm_translate_key_event(event);
	cd = mbm_translate_key_code(event, code);		 

	if (g_am_key_handler)
	{
		(*g_am_key_handler)(evt, cd);
	}
}

static void mbm_pen_down_handler(Int8 type, u32 x, u32 y)
{
	mbm_trace("mbm_pen_down_handler type=%d, g_am_tp_handler = %x", type, g_am_tp_handler);
    if (g_am_tp_handler)
    {
        g_am_tp_handler(MBM_TP_EVENT_DOWN, x, y);    
    }
}

static void mbm_pen_up_handler(Int8 type, u32 x, u32 y)
{
	mbm_trace("mbm_pen_up_handler type=%d, g_am_tp_handler =%x", type, g_am_tp_handler);
	
    if (g_am_tp_handler)
    {
        g_am_tp_handler(type, x, y);    
    }
}

static void mbm_pen_move_handler(Int8 type, u32 x, u32 y)
{
	mbm_trace("mbm_pen_move_handler type=%d, g_am_tp_handler =%x", type, g_am_tp_handler);
	
    if (g_am_tp_handler)
    {
        g_am_tp_handler(type, x, y);    
    }
}


void mbm_am_scr_reg_tp_handler(Int8 type, u32 x, u32 y)
{
	mbm_trace("mbm_am_scr_reg_tp_handler type=%d", type);
	
	switch(type)
	{
	case VEN_TS_EVENT_PRESS:
		mbm_pen_down_handler(MBM_TP_EVENT_DOWN, x, y);
		break;
	case VEN_TS_EVENT_RELEASE:
		mbm_pen_up_handler(MBM_TP_EVENT_UP, x, y);
		break;
	case VEN_TS_EVENT_MOVE:
		mbm_pen_move_handler(MBM_TP_EVENT_MOVE, x, y);
		break;
	default:
		mbm_trace("mbm_am_scr_reg_tp_handler unsuport type. type=%d", type);
		break;
	}
}


//static function
void mbm_am_reg_key_handler(t_mbm_keyhandler hdr)
{
	mbm_trace("mbm_am_reg_key_handler");
	g_am_key_handler = hdr;
}

void mbm_am_excute_key_handler(Int32 key_event, Int32 key_code)
{
	mbm_trace("mbm_am_excute_key_handler key_event=%d", key_event);
	
	if(g_am_key_handler != NULL)
	{
		g_am_key_handler(key_event, key_code);
	}
}

void mbm_am_reg_tp_handler(t_mbm_tphandler hdr)
{
	mbm_trace("mbm_am_reg_tp_handler");
	
	g_am_tp_handler = hdr;
}

void mbm_am_excute_tp_handler(Int32 tp_event, Int32 x, Int32 y)
{
	mbm_trace("mbm_am_excute_key_handler tp_event=%d", tp_event);
	
	if(g_am_tp_handler != NULL)
	{
		g_am_tp_handler(tp_event, x, y);
	}
}

void mbm_am_reg_state_handler(t_mbm_applet_state_handler hdr)
{
	mbm_trace("mbm_am_reg_state_handler ");
	g_am_state_handler = hdr;
}

void mbm_am_excute_state_handler(Int32 state)
{
	mbm_trace("mbm_am_excute_state_handler state=%d", state);
	if(g_am_state_handler != NULL)
	{
		g_am_state_handler(state, 0);
	}
}

#endif /* MBM_IMIWORLD_SUPPORT */
